/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import model.BillDetailModel;
import util.DataUtil;

/**
 *
 * @author ThanhToan
 */
public class BillDetailDAO {
    public static boolean insertExportBill(BillDetailModel obj){
         boolean result = false;
         try {
            CallableStatement csmt = DataUtil.getConnection().prepareCall("{call sp_insertBillDetail(?,?,?,?,?)}");
            csmt.setString("billID", obj.getBillID());
            csmt.setString("productID", obj.getProductID());
            csmt.setString("number", obj.getNumber());
            csmt.setString("price", obj.getPrice());
            csmt.setString("amount", obj.getAmount());
            result = DataUtil.executeNonStore(csmt);
         } catch (Exception e) {
             e.printStackTrace();
             result = false;
         }
         return result;
     }

    public static ArrayList<BillDetailModel> getBillByIEID(String id){
         ArrayList<BillDetailModel> billList  = new ArrayList<BillDetailModel>();
         try {
            CallableStatement csmt = DataUtil.getConnection().prepareCall("{call sp_getBillByIEID(?)}");
            csmt.setString("id", id);
            ResultSet rs = DataUtil.executeStore(csmt);
            while(rs.next()){
                BillDetailModel obj = new BillDetailModel();
                obj.setId(rs.getString("ID"));
                obj.setBillID(rs.getString("BillID"));
                obj.setProductID(rs.getString("ProductID"));
                obj.setNumber(rs.getString("Number"));
                obj.setPrice(rs.getString("Price"));
                obj.setAmount(rs.getString("Amount"));
                obj.setProductName(rs.getString("ProductName"));
                obj.setDiscount(rs.getString("Discount"));
                billList.add(obj);
            }
         } catch (Exception e) {
             e.printStackTrace();
         }
         return billList;
     }
}
